from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime
import time


class AccountBase(BaseModel):
    code: str = Field(..., description="账套编码")
    name: str = Field(..., description="账套名称")
    description: Optional[str] = Field(None, description="账套描述")
    enabled: bool = Field(True, description="启用状态")


class AccountCreate(AccountBase):
    pass


class AccountUpdate(BaseModel):
    code: Optional[str] = Field(None, description="账套编码")
    name: Optional[str] = Field(None, description="账套名称")
    description: Optional[str] = Field(None, description="账套描述")
    enabled: Optional[bool] = Field(None, description="启用状态")


class Account(AccountBase):
    id: str
    create_time: int
    update_time: int

    class Config:
        orm_mode = True
        from_attributes = True


# 分页相关的Schema
class PaginationMeta(BaseModel):
    total_items: int = Field(..., description="总记录数")
    total_pages: int = Field(..., description="总页数")
    current_page: int = Field(..., description="当前页")
    page_size: int = Field(..., description="每页大小")


class PaginationLinks(BaseModel):
    self: str = Field(..., description="当前页链接")
    first: str = Field(..., description="首页链接")
    next: Optional[str] = Field(None, description="下一页链接")
    last: str = Field(..., description="最后一页链接")


class PaginationMetaWrapper(BaseModel):
    pagination: PaginationMeta = Field(..., description="分页信息")


class AccountListResponse(BaseModel):
    data: List[Account] = Field(..., description="账套列表数据")
    meta: PaginationMetaWrapper = Field(..., description="分页元信息")
    links: PaginationLinks = Field(..., description="分页链接")